/*
ID: icerupt1
PROG: starry
LANG: C++11
*/

/* solution
 *
 * good for coding and abstract ability.
 * 这题其实很简单。。。关键看你敢不敢写。
 * 另外这个实现比较渣，等下弄个优美的实现。
 *
*/
#include <fstream>
#include <iostream>
#include <queue>
#include <vector>

std::ifstream fin {"starry.in" };
std::ofstream fout{"starry.out"};

struct hw { int h, w; };

bool operator<(hw const & a, hw const & b)
{
	return a.h < b.h || (a.h == b.h && a.w < b.w);
}

int const opt[8][2] = {{0, +1}, {+1, +1}, {+1, 0}, {+1, -1},
					   {0, -1}, {-1, -1}, {-1, 0}, {-1, +1}};
int const maxn = 102;
hw right_down[maxn][maxn];
hw left_up[maxn][maxn];
char da[maxn][maxn];
char dest[maxn][maxn];
int color[maxn][maxn];
bool vis[maxn][maxn];
int w, h;

std::vector<hw> start_pos;

bool inrange(int ph, int pw)
{
	return (0 <= ph && ph < h) && (0 <= pw && pw < w);
}

void color_dest(int x, int y, int x1, int y1, char ch, int co)
{
	for (auto i = x; i <= x1; i++)
		for (auto j = y; j <= y1; j++)
			if (color[i][j] == co) dest[i][j] = ch;
}

hw  trans_point(int t, int x, int y, int h, int w)
{														// inverse
	if (t == 0) return hw{x, y};						// 0
	if (t == 1) return hw{h - x - 1, y};				// 1
	if (t == 2) return hw{h - x - 1, w - y - 1};		// 2
	if (t == 3) return hw{x, w - y - 1};				// 3
	if (t == 4) return hw{y, h - x - 1};				// 5
	if (t == 5) return hw{w - y - 1, x};				// 4
	if (t == 6) return hw{w - y - 1, h - x - 1};		// 6
	/*if (t == 7)*/ return hw{y, x};					// 7
}

bool check_trans(int t, int x1, int y1, int x2, int y2, int co1, int u1, int v1, int u2, int v2, int co2)
{
	int h1 = x2 - x1 + 1, w1 = y2 - y1 + 1;
	int h2 = u2 - u1 + 1, w2 = v2 - v1 + 1;	// FIXME
	h2 = w2;

	for (int i = 0; i < h1; i++)
		for (int j = 0; j < w1; j++)
			if (color[x1 + i][y1 + j] == co1) {
				hw tmp = trans_point(t, i, j, h1, w1);
				tmp.h += u1;  tmp.w += v1;
				if (!inrange(tmp.h, tmp.w)) return false;
				if (color[tmp.h][tmp.w] != co2) return false;
			}
	return true;
}

int const inverse[8] = {0, 1, 2, 3, 5, 4, 6, 7};

bool check(int x1, int y1, int x2, int y2, int co1, int u1, int v1, int u2, int v2, int co2)
{
	int h1 = x2 - x1 + 1, w1 = y2 - y1 + 1;
	int h2 = u2 - u1 + 1, w2 = v2 - v1 + 1;

	if (!((h1 == h2 && w1 == w2) || (h1 == w2 && w1 == h2))) return false;

	for (int trans = 0; trans < 8; trans++)
		if (check_trans(trans, x1, y1, x2, y2, co1, u1, v1, u2, v2, co2) &&
				check_trans(inverse[trans], u1, v1, u2, v2, co2, x1, y1, x2, y2, co1))
			return true;

	return false;
}

int main()
{
	fin >> w >> h;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) fin >> da[i][j];

	// color
	for (int i = 0, co = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			if (color[i][j] || da[i][j] == '0') continue;
			std::queue<hw> q;
			q.push({i, j});
			color[i][j] = ++co;
			right_down[i][j] = hw{i, j};
			left_up[i][j] = hw{i, j};
			start_pos.push_back(hw{i, j});
			while (!q.empty()) {
				hw now = q.front(); q.pop();
				for (int adj = 0; adj < 8; adj++) {
					hw p{now.h + opt[adj][0], now.w + opt[adj][1]};
					if (inrange(p.h, p.w) && da[p.h][p.w] == '1' && !color[p.h][p.w]) {
						q.push(p);
						color[p.h][p.w] = co;
						right_down[i][j].h = std::max(right_down[i][j].h, p.h);
						right_down[i][j].w = std::max(right_down[i][j].w, p.w);
						left_up[i][j].w = std::min(left_up[i][j].w, p.w);
					}
				}
			}
		}

	char const space_char = '0';
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) dest[i][j] = space_char;

	int co = 0;
	for (auto it = start_pos.begin(); it != start_pos.end(); ++it) {
		int i = (*it).h, j = (*it).w;
		if (dest[i][j] != space_char || da[i][j] == '0') continue;
		co++;
		color_dest(i, left_up[i][j].w, right_down[i][j].h, right_down[i][j].w,
					'a' + co - 1, color[i][j]);
		for (auto match = it + 1; match != start_pos.end(); ++match) {
			int pi = (*match).h, pj = (*match).w;
			if (i == 0 && j == 15) std::cout << "--->" << pi << ' ' << pj << '\n';
			if (dest[pi][pj] != space_char) continue;
			if (check(i, left_up[i][j].w, right_down[i][j].h, right_down[i][j].w, color[i][j],
						pi, left_up[pi][pj].w, right_down[pi][pj].h, right_down[pi][pj].w, color[pi][pj]))
				color_dest(pi, left_up[pi][pj].w, right_down[pi][pj].h, right_down[pi][pj].w,
								'a' + co - 1, color[pi][pj]);
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) std::cout << dest[i][j];
			std::cerr << '\n';
		}
		std::cerr << '\n';
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			std::cout << dest[i][j];
			fout << dest[i][j];
		}
		std::cout << '\n';
		fout << '\n';
	}
}

